package academia.gui;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTextPane;
import java.awt.List;
import java.awt.SystemColor;
import javax.swing.JLabel;
import com.jgoodies.forms.factories.DefaultComponentFactory;
import java.awt.Font;

import academia.negocio.ConverteTipo;
import academia.persistencia.PseudoBanco;

import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.TextField;
import java.awt.Color;

public class Cadastrados extends JFrame {

	private JPanel contentPane;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Cadastrados frame = new Cadastrados();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	
	public Cadastrados() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBackground(SystemColor.inactiveCaptionBorder);
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		List listCadastrados = new List();		
		listCadastrados.setBounds(10, 52, 414, 175);
		contentPane.add(listCadastrados);
		
		PseudoBanco.setListaNomes();
		
		for (int n = 0; n < PseudoBanco.sizeListaNomes(); n++) {  
			listCadastrados.add(PseudoBanco.getListaNomes(n));
		}
	
		
		JLabel lblPessoasCadastradas = DefaultComponentFactory.getInstance().createLabel("Pessoas Cadastradas");
		lblPessoasCadastradas.setForeground(SystemColor.controlShadow);
		lblPessoasCadastradas.setFont(new Font("Dialog", Font.BOLD, 20));
		lblPessoasCadastradas.setBounds(110, 11, 324, 35);
		contentPane.add(lblPessoasCadastradas);
		
		JButton btnMenu = new JButton("Menu");
		btnMenu.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				new MenuRoot().setVisible(true);
				dispose();
				
			}
		});
		btnMenu.setBounds(10, 22, 80, 23);
		contentPane.add(btnMenu);
		
		final TextField textCpf = new TextField();
		textCpf.setBounds(90, 234, 200, 22);
		contentPane.add(textCpf);
		
		JButton btnBuscar = new JButton("Buscar Dados");
		btnBuscar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				for(int n = 0; n < PseudoBanco.sizeListaPessoa(); n++){
					if (PseudoBanco.getCpf(n).equals(textCpf.getText())) {
						PseudoBanco.setPosicao(n);
						if (PseudoBanco.getTipo(n).equals("Instrutor")) {
							new TelaDadosInstrutor().setVisible(true);
							dispose();
						} else if (PseudoBanco.getTipo(n).equals("Cliente")) {
							new TelaDadosCliente().setVisible(true);
							dispose();
						}
						
					}else {
						textCpf.setText("Cpf nao encontrado");
					}
					
				}
			}
		});
		btnBuscar.setBounds(307, 233, 117, 23);
		contentPane.add(btnBuscar);
		
		
		
		JLabel label = new JLabel("CPF");
		label.setForeground(Color.BLACK);
		label.setFont(new Font("Tahoma", Font.PLAIN, 14));
		label.setBounds(63, 233, 46, 22);
		contentPane.add(label);
	}
}
